const db = require("./index");

// //用户-部门组织关联表
// db.user.belongsToMany(db.department, { through: db.user_department,as: "MyDepartment"   });
// db.department.belongsToMany(db.user, { through: db.user_department });

//用户-项目关联表
db.user.belongsToMany(db.project, {
  through: db.user_project,
  as: "MyProject",
});
db.project.belongsToMany(db.user, { through: db.user_project, as: "Member" });

//用户-需求关联表
db.user.belongsToMany(db.need, { through: db.user_need, as: "MyNeed" });
db.need.belongsToMany(db.user, { through: db.user_need, as: "Handler" });

//需求-项目关联
db.project.hasMany(db.need, { as: "Need" });

//需求-需求历史关联
db.need.hasMany(db.needHistory, { as: "History" });

// 需求和父级需求的关联
Need.belongsTo(Need, { as: "ParentNeed", foreignKey: "parentId" });
Need.hasMany(Need, { as: "ChildNeed", foreignKey: "parentId" });

// // 前置依赖、后置依赖
// Need.belongsToMany(Need, {
//   through: "need_dependency",
//   as: "Dependency",
//   foreignKey: "needId",
//   otherKey: "dependentNeedId",
// });

// 缺陷-需求关联  缺陷的关联需求
db.bug.belongsTo(db.need, { as: "Need", foreignKey: "needId" });

//缺陷-项目关联
db.project.hasMany(db.bug, { as: "Bug" });
//缺陷-缺陷历史关联
db.bug.hasMany(db.bugHistory, { as: "History" });

//用户-缺陷关联表
db.user.belongsToMany(db.bug, { through: db.user_bug, as: "MyBug" });
db.bug.belongsToMany(db.user, { through: db.user_bug, as: "Handler" });
